package com.example.li_han.servlet;

import com.example.li_han.pojo.News;
import com.example.li_han.pojo.User;
import com.example.li_han.service.NewsService;
import com.example.li_han.service.UserService;
import com.example.li_han.utils.RndImage;
import com.google.gson.Gson;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//验证码
/**
 * @author Administrator
 */
@WebServlet(name = "NumServlet", value = "/NumServlet")

public class NumServlet extends HttpServlet {
    private String message;
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
//产生一个五位数的字符串
        String num = RndImage.random();
        //保存--会话机制SessionId

//        HttpSession  session = request.getSession(true);
//        session.setAttribute("checkNum",num);//保存
        HttpSession session  = request.getSession();
        session.setAttribute("checkNum",num);//保存
        System.out.println(num);

        response.setContentType("image/jpeg");
        RndImage.imageOut(num,response.getOutputStream(),130,30);

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    }

}